<template>
  <div>
    <div class="flex justify-center">
      <div class="bg-white">
        <div class="w-24">
          <div class="px-2 pt-2">{{ sensor.no }}</div>
          <img class="w-full mx-auto" src="../../../assets/images/sensor1.jpg" alt="" />
        </div>
        <div class="flex justify-around">
          <a-button type="link" @click="onEdit">设置</a-button>
          <a-button type="link" @click="$emit('on-delete', { type: 'sensor', id: sensor.id })"
            >删除</a-button
          >
        </div>
      </div>
    </div>
    <sensor-modal ref="senM" @edit="edit" />
  </div>
</template>
    
    <script>
import { message } from 'ant-design-vue';
import sensorModal from './modal/sensor.vue';
import { defHttp } from '/@/utils/http/axios';

export default {
  props: ['sensor'],
  components: { sensorModal },
  created() {},
  methods: {
    onEdit() {
      this.$refs.senM.open(this.sensor);
    },
    edit(form) {
      defHttp
        .post({
          url: '/sensor/update',
          params: {
            ...form,
            id: this.sensor.id,
            projectId: this.sensor.projectId,
            gatherDeviceId: this.sensor.gatherDeviceId,
            name: this.sensor.name,
            dtuId: this.sensor.dtuId,
            companyId: 1 * form.companyId,
          },
        })
        .then((res) => {
          if (!res.rst) {
            message.error(res.data);
          } else {
            this.$emit('updated');
            message.success('操作成功');
          }
        });
    },
  },
};
</script>
    
    <style>
</style>